<?php
/**
 * Created by PhpStorm.
 * User: zyark
 * Date: 2018/4/13
 * Time: 08:56
 */

namespace app\index\logic;


use app\common\model\Page;

class OrderLogic
{
    /**
     * 获取缴费信息
     * @param $data
     * @return mixed
     */
    public function getPaymentRecords($data){
        $map = [];
        if(!isset($data['page_size'])){
            $data['page_size'] = 10;
        }
        if(!isset($data['page_num'])){
            $data['page_num'] = 1;
        }
        if(isset($data['user_id']) && !empty($data['user_id'])){
            $map['user_id'] = $data['user_id'];
        }
        $result = $this->queryByMap($map,$data['page_num'],$data['page_size']);
        foreach ($result['list'] as $key=>&$value){
            $value['house_property'] = model('HouseProperty')
                ->where(array('id'=>$value['house_property_id']))
                ->field('building_number,floor_number,room_number,detail')
                ->find();
        }
        unset($value);
        return $result;
    }

    private function queryByMap($map,$page_num,$page_size){
        $startno = ($page_num - 1) * $page_size;
        $map['status'] = 1;
        $list = model('Order')
            ->where($map)
            ->limit($startno,$page_size)
            ->order('id','desc')
            ->field('order_sn',true)
            ->select();
        $count = model('Order')
            ->where($map)
            ->count();
        $result['list'] = $list;
        $page = new Page($page_num,$count,$page_size);
        $result['page'] = $page;
        return $result;
    }
}